var config = require("../../config");

//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {}
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this;
    that.setData({
      userInfo: app.globalData.userInfo
    })
  },

  formSubmit: function (e) {
    var that = this;
    var data = e.detail.value;
    console.log(data);
    var my_id = that.data.userInfo.id;
    var say = data.say;

    if (say == '') {
      wx.showToast({
        title: '你还未输入信息',
        icon: 'success',
        duration: 1000
      })
      return;
    }

    wx.request({
      url: config.urls.save_say,
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        user_id: my_id,
        say: say
      },

      success: function (res) {
        if (res.data.success) {
          wx.showToast({
            title: '修改成功',
            icon: 'success',
            duration: 1500
          })
          wx.navigateBack({
            delta: 1
          })
        }
        else {
          wx.showToast({
            title: '修改失败',
            icon: 'loading',
            duration: 1500
          })
          console.log("say modify failed.");
        }
      }
    });


  }
})
